import {createApp} from 'vue'
import '@/styles/index.scss'
import App from './App.vue'

import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';

import mixin from '@/utils/mixin';
import {filters} from '@/utils/filters.js';

const app = createApp(App);

// 路由
import router from '@/router';

import * as ElementPlusIconsVue from '@element-plus/icons-vue';

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}

app.use(router);

app.use(ElementPlus);

// 混入 -- 抽取公用的实例（操作成功与失败消息提醒内容等）
app.mixin(mixin);


app.config.globalProperties.$filters = filters;


app.mount('#app')

// pinia
import {createPinia} from 'pinia';

const pinia = createPinia();
app.use(pinia);
// store
import store from '@/store';

app.config.globalProperties.$store = store;

// 持久化存储
import {createPersistedState} from 'pinia-plugin-persistedstate';

pinia.use(
    createPersistedState({
        auto: true, // 启用所有 Store 默认持久化
    }),
);

//配置全局api
import api from '@/api'

app.config.globalProperties.$api = api

// 全局组件注册
import myComponent from '@/components/index';

Object.keys(myComponent).forEach((key) => {
    app.component(key, myComponent[key]);
});